package pretice.p3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.TreeSet;

public class Prize extends Thread{
    ArrayList<Integer>arrayList;
    public Prize() {
    }

    public Prize(ArrayList<Integer> arrayList) {
        this.arrayList=arrayList;
    }

    @Override
    public void run() {
        TreeSet<Integer> arrayList1=new TreeSet<>();
        while (true){
            synchronized (Prize.class){
                if (arrayList.size()==0){
                    System.out.println(getName() + "抽中了" +arrayList1);
                    break;
                }else {
                    Collections.shuffle(arrayList);
                    Integer remove = arrayList.remove(0);
                    arrayList1.add(remove);
                    //System.out.println(getName() + "抽中了" + remove + "元");
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
